package com.qd.common.panda.domain.entity.transfer;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.cdqidi.util.page.BaseQuery;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Optional;

/**
 * 待转账金额
 *
 * @author sjk
 * @create 2023-09-07 10:54
 * @since 1.0.0
 */
@Getter
@Setter
@Accessors(chain = true)
public class UserToBeTransferDTO extends BaseQuery {
    @ExcelIgnore
    @JsonIgnore
    private static final String EXCEL_TITLE = "待转账信息";
    /**
     * 收款用户ID
     */
    @ExcelProperty(value = {EXCEL_TITLE, "用户ID"})
    private String userId;
    /**
     * 收款用户名
     */
    @ExcelProperty(value = {EXCEL_TITLE, "用户名"})
    private String userName;
    /**
     * 收款人手机号
     */
    @ExcelProperty(value = {EXCEL_TITLE, "手机号"})
    private String mobile;
    /**
     * 收款卡号
     */
    @ExcelProperty(value = {EXCEL_TITLE, "卡号"})
    private String cardNumber;
    /**
     * 开户银行
     */
    @ExcelProperty(value = {EXCEL_TITLE, "开户银行"})
    private String openBank;
    /**
     * 总金额
     */
    @JsonIgnore
    @ExcelIgnore
    private BigDecimal totalRevenue;
    /**
     * 总金额显示
     */
    @ExcelProperty(value = {EXCEL_TITLE, "总金额"})
    private String totalRevenueDisplay;
    /**
     * 已转账金额
     */
    @JsonIgnore
    @ExcelIgnore
    private BigDecimal transferAmount;
    /**
     * 已转账金额显示
     */
    @ExcelProperty(value = {EXCEL_TITLE, "已转账金额"})
    private String transferAmountDisplay;
    /**
     * 待转金额
     */
    @JsonIgnore
    @ExcelIgnore
    private BigDecimal deductionTotalRevenue;
    /**
     * 待转金额显示
     */
    @ExcelProperty(value = {EXCEL_TITLE, "待转金额"})
    private String deductionTotalRevenueDisplay;
    /**
     * 扣费金额
     */
    @JsonIgnore
    @ExcelIgnore
    private BigDecimal deductionAmount;
    /**
     * 扣费金额显示
     */
    @ExcelProperty(value = {EXCEL_TITLE, "扣费金额"})
    private String deductionAmountDisplay;
    /**
     * 分成比例
     */
    @JsonIgnore
    @ExcelIgnore
    private Double shareRatio;
    /**
     * 分成比例显示
     */
    @ExcelProperty(value = {EXCEL_TITLE, "分成比例"})
    private String shareRatioDisplay;

    public String getTransferAmountDisplay() {
        return Optional.ofNullable(transferAmount).orElse(new BigDecimal("0")).stripTrailingZeros().toPlainString();
    }

    public String getTotalRevenueDisplay() {
        return Optional.ofNullable(totalRevenue).orElse(new BigDecimal("0")).stripTrailingZeros().toPlainString();
    }

    public String getDeductionTotalRevenueDisplay() {
        return Optional.ofNullable(deductionTotalRevenue).orElse(new BigDecimal("0")).stripTrailingZeros().toPlainString();
    }

    public String getDeductionAmountDisplay() {
        return Optional.ofNullable(deductionAmount).orElse(new BigDecimal("0")).stripTrailingZeros().toPlainString();
    }

    public String getShareRatioDisplay() {
        if (null == shareRatio || shareRatio <= 0) {
            return "0";
        }
        return new BigDecimal(shareRatio).divide(new BigDecimal("10"), RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
    }

    @Override
    public void freeData() {
        super.freeData();
    }
}